﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Controls;

namespace PRO_DOCS.BLL.WIN
{
    public class CustomDataTypes : DAL.Database.MainClass
    {
        /// <summary>
        /// 
        /// </summary>
        public class AssetCategoriesMoreInfoSorter : IComparer<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX>
        {
            public int Compare(DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_A, DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_B)
            {
                return aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_A.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value.CompareTo(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_B.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value);
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public enum InputDataTypes : int
        {
            /// <summary>
            /// 
            /// </summary>
            Numeric = 1,
            /// <summary>
            /// 
            /// </summary>
            Decimal,
            /// <summary>
            /// 
            /// </summary>
            Text,
            /// <summary>
            /// 
            /// </summary>
            FreeText,
            /// <summary>
            /// 
            /// </summary>
            Multiselect,
            /// <summary>
            /// 
            /// </summary>
            TrueFalse,
            /// <summary>
            /// 
            /// </summary>
            Date,
            /// <summary>
            /// 
            /// </summary>
            Country,
            /// <summary>
            /// 
            /// </summary>
            Nationality,
            /// <summary>
            /// 
            /// </summary>
            OptionalValue,
            /// <summary>
            /// 
            /// </summary>
            Time,
            N_A
        }

        /// <summary>
        /// Adds the label.
        /// </summary>
        /// <param name="displayText">The display text.</param>
        /// <param name="rowIndex">Index of the row.</param>
        private void ADD_DISPLAY_LABEL(TableLayoutPanel usedTableLayoutPanel, string displayText, int rowIndex)
        {
            Label lblDisplayText = new Label();
            lblDisplayText.Text = displayText + " :";
            lblDisplayText.Anchor = AnchorStyles.Right;
            lblDisplayText.AutoSize = true;
            usedTableLayoutPanel.Controls.Add(lblDisplayText, 0, rowIndex);
        }
        /// <summary>
        /// Adds the control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="displayText">The display text.</param>
        /// <param name="rowIndex">Index of the row.</param>
        private void ADD_CUSTOM_CONTROL(TableLayoutPanel usedTableLayoutPanel, Control control, string displayText, int rowIndex)
        {
            ADD_DISPLAY_LABEL(usedTableLayoutPanel, displayText, rowIndex);
            usedTableLayoutPanel.Controls.Add(control, 1, rowIndex);
            usedTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
            usedTableLayoutPanel.RowStyles[rowIndex].SizeType = SizeType.AutoSize;
        }
        private void ADD_CUSTOM_SEARCH_CONTROL(TableLayoutPanel usedTableLayoutPanel, Control comboOperations, Control control, string displayText, int rowIndex)
        {
            ADD_DISPLAY_LABEL(usedTableLayoutPanel, displayText, rowIndex);
            usedTableLayoutPanel.ColumnStyles.Add(new ColumnStyle());
            usedTableLayoutPanel.ColumnStyles[0].SizeType = SizeType.AutoSize;
            comboOperations.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            if (comboOperations.Visible)
            {
                usedTableLayoutPanel.Controls.Add(comboOperations, 1, rowIndex);
                usedTableLayoutPanel.ColumnStyles.Add(new ColumnStyle());
                usedTableLayoutPanel.ColumnStyles[1].SizeType = SizeType.AutoSize;
                usedTableLayoutPanel.Controls.Add(control, 2, rowIndex);
                usedTableLayoutPanel.ColumnStyles.Add(new ColumnStyle());
                usedTableLayoutPanel.ColumnStyles[2].SizeType = SizeType.AutoSize;
            }
            else
            {
                usedTableLayoutPanel.SetColumnSpan(control, 2);


                usedTableLayoutPanel.Controls.Add(control, 1, rowIndex);
                usedTableLayoutPanel.ColumnStyles.Add(new ColumnStyle());
                usedTableLayoutPanel.ColumnStyles[1].SizeType = SizeType.AutoSize;

            }
            control.Anchor = AnchorStyles.Left | AnchorStyles.Right;
            usedTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
            usedTableLayoutPanel.RowStyles[rowIndex].SizeType = SizeType.AutoSize;
        }
        /// <summary>
        /// Types the index control.
        /// </summary>
        /// <param name="IndexDataType">Type of the index data.</param>
        /// <param name="typeIndex">Index of the type.</param>
        /// <param name="displayOrder">The display order.</param>
        private void ADD_CUSTOM_CONTROL_BY_DATA_TYPE(TableLayoutPanel usedTableLayoutPanel,
                                             DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX)
        {
            InputDataTypes inputDataType = (InputDataTypes)aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DATA_TYPE_ID.Value;
            Control control = null;
            switch (inputDataType)
            {
                #region Numeric & Decimal:
                case InputDataTypes.Numeric:
                case InputDataTypes.Decimal:
                    {
                        DevExpress.XtraEditors.SpinEdit spinEdit1 = new DevExpress.XtraEditors.SpinEdit();
                        spinEdit1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        spinEdit1.Properties.Mask.EditMask = (inputDataType.Equals(InputDataTypes.Decimal)) ? "f" : "f0";
                        spinEdit1.Size = new System.Drawing.Size(160, 0);
                        spinEdit1.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        spinEdit1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        spinEdit1.Properties.MinValue = -999999999999999;
                        spinEdit1.Properties.MaxValue = 999999999999999;
                        control = spinEdit1;
                    }
                    break;
                #endregion
                #region Text
                case InputDataTypes.Text:
                    {

                        DevExpress.XtraEditors.TextEdit textEdit1 = new DevExpress.XtraEditors.TextEdit();
                        textEdit1.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        textEdit1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        textEdit1.Size = new System.Drawing.Size(310, 20);
                        textEdit1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        control = textEdit1;
                    }
                    break;
                #endregion
                #region Free Text
                case InputDataTypes.FreeText:
                    {
                        DevExpress.XtraEditors.MemoEdit memoEdit1 = new DevExpress.XtraEditors.MemoEdit();
                        memoEdit1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        memoEdit1.Size = new System.Drawing.Size(310, 90);
                        memoEdit1.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        memoEdit1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        control = memoEdit1;
                    }
                    break;
                #endregion
                #region Multiselect
                case InputDataTypes.Multiselect:
                    {
                        DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl1 = new DevExpress.XtraEditors.CheckedListBoxControl();
                        checkedListBoxControl1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        checkedListBoxControl1.Size = new System.Drawing.Size(310, 120);
                        checkedListBoxControl1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value; ;

                        List<string> defaultSelectedValues = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Split(';').ToList();
                        List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION> aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS =
                            (from multiinfo in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONs
                             where multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                             orderby multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_DISPLAY_ORDER.Value
                             select multiinfo).ToList();

                        checkedListBoxControl1.BeginUpdate();
                        checkedListBoxControl1.Items.Clear();

                        for (int i = 0; i < aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS.Count; i++)
                        {
                            CheckedListBoxItem listViewItem = new CheckedListBoxItem();
                            listViewItem.Value = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME;
                            listViewItem.Description = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME;

                            checkedListBoxControl1.Items.Add(listViewItem);

                            if (defaultSelectedValues.Contains(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME))
                            {
                                checkedListBoxControl1.SetItemChecked(i, true);

                            }
                        }
                        checkedListBoxControl1.EndUpdate();

                        control = checkedListBoxControl1;
                    }
                    break;
                #endregion
                #region True & False
                case InputDataTypes.TrueFalse:
                    {

                        DevExpress.XtraEditors.ComboBoxEdit comboTrueFalse = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboTrueFalse.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboTrueFalse.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        comboTrueFalse.Width = 310;
                        comboTrueFalse.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

                        comboTrueFalse.Properties.Items.BeginUpdate();
                        comboTrueFalse.Properties.Items.Clear();

                        DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION =
                            (from bitOptions in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTIONs
                             where bitOptions.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                             select bitOptions).FirstOrDefault();


                        comboTrueFalse.Properties.Items.Add(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION.BIT_OPTION_TRUE_DISPLAY_NAME);
                        comboTrueFalse.Properties.Items.Add(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION.BIT_OPTION_FALSE_DISPLAY_NAME);

                        comboTrueFalse.Properties.Items.EndUpdate();
                        comboTrueFalse.SelectedIndex = -1;
                        comboTrueFalse.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboTrueFalse;
                    }
                    break;
                #endregion
                #region Date
                case InputDataTypes.Date:
                    {
                        DevExpress.XtraEditors.DateEdit datePicker = new DevExpress.XtraEditors.DateEdit();

                        DateTime datetimePickerValue = DateTime.Now;

                        if (String.IsNullOrEmpty(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE))
                        {
                            datePicker.EditValue = null;
                        }
                        else if (aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Equals("GETDATE"))
                        {
                            datePicker.EditValue = DateTime.Now;
                        }
                        else
                        {
                            List<string> current_default_string = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Split('-').ToList();
                            int day = Convert.ToInt32(current_default_string[0]);
                            int month = Convert.ToInt32(current_default_string[1]);
                            int year = Convert.ToInt32(current_default_string[2]);
                            datetimePickerValue = new DateTime(year, month, day);
                            datePicker.EditValue = datetimePickerValue;
                        }


                        datePicker.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        datePicker.Properties.CalendarTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
                        datePicker.Properties.CalendarTimeProperties.CloseUpKey = new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.F4);
                        datePicker.Properties.CalendarTimeProperties.PopupBorderStyle = DevExpress.XtraEditors.Controls.PopupBorderStyles.Default;
                        datePicker.Size = new System.Drawing.Size(310, 20);
                        datePicker.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;

                        //DateTimePicker datePicker = new DateTimePicker();
                        //datePicker.Name = 
                        //datePicker.Value = datetimePickerValue;
                        //datePicker.TabIndex =  ;

                        control = datePicker;
                    }
                    break;
                #endregion
                #region Time
                case InputDataTypes.Time:
                    {
                        DevExpress.XtraEditors.TimeEdit timepicker = new DevExpress.XtraEditors.TimeEdit();
                        DateTime timePickerValue = (aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Equals("GETDATE") || String.IsNullOrEmpty(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE) || !DateTime.TryParse(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE, out timePickerValue)) ? DateTime.Now : DateTime.Parse(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE);
                        timepicker.EditValue = timePickerValue;
                        timepicker.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        timepicker.Properties.CloseUpKey = new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.F4);
                        timepicker.Properties.Mask.EditMask = "t";
                        timepicker.Properties.PopupBorderStyle = DevExpress.XtraEditors.Controls.PopupBorderStyles.Default;
                        timepicker.Size = new System.Drawing.Size(200, 20);
                        timepicker.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value; ;

                        control = timepicker;
                    }
                    break;
                #endregion
                #region Country
                case InputDataTypes.Country:
                    {
                        DevExpress.XtraEditors.ComboBoxEdit comboCountries = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboCountries.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboCountries.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        comboCountries.Width = 310;
                        comboCountries.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

                        DAL.AppCode.Countries.LoadAllCountriesToComboBox(comboCountries);

                        comboCountries.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboCountries;
                    }
                    break;
                #endregion
                #region Nationality
                case InputDataTypes.Nationality:
                    {
                        DevExpress.XtraEditors.ComboBoxEdit comboNationalities = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboNationalities.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboNationalities.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        comboNationalities.Width = 310;
                        comboNationalities.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

                        DAL.AppCode.Countries.LoadAllNationalitiesToComboBox(comboNationalities);

                        comboNationalities.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboNationalities;
                    }
                    break;
                #endregion
                #region Optional Value
                case InputDataTypes.OptionalValue:
                    {
                        DevExpress.XtraEditors.ComboBoxEdit comboOptionalValue = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboOptionalValue.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboOptionalValue.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        comboOptionalValue.Width = 310;
                        comboOptionalValue.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;


                        List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION> aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS =
                            (from multiinfo in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONs
                             where multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                             orderby multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_DISPLAY_ORDER.Value
                             select multiinfo).ToList();

                        comboOptionalValue.Properties.Items.BeginUpdate();
                        comboOptionalValue.Properties.Items.Clear();

                        for (int i = 0; i < aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS.Count; i++)
                        {
                            comboOptionalValue.Properties.Items.Add(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME);
                        }
                        comboOptionalValue.Properties.Items.EndUpdate();

                        comboOptionalValue.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboOptionalValue;
                    }
                    break;
                #endregion
            }
            control.Tag = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_IS_REQUIRED.Value;
            ADD_CUSTOM_CONTROL(usedTableLayoutPanel,
                       control,
                       aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_NAME,
                       aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value);
        }


        /// <summary>
        /// Types the index control.
        /// </summary>
        /// <param name="IndexDataType">Type of the index data.</param>
        /// <param name="typeIndex">Index of the type.</param>
        /// <param name="displayOrder">The display order.</param>
        private void ADD_CUSTOM_SEARCH_CONTROL_BY_DATA_TYPE(TableLayoutPanel usedTableLayoutPanel,
                                             DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX)
        {
            InputDataTypes inputDataType = (InputDataTypes)aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DATA_TYPE_ID.Value;
            Control control = null;
            DevExpress.XtraEditors.ComboBoxEdit comboOperations = new DevExpress.XtraEditors.ComboBoxEdit();
            comboOperations.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
            switch (inputDataType)
            {
                #region Numeric & Decimal:
                case InputDataTypes.Numeric:
                case InputDataTypes.Decimal:
                    {
                        DevExpress.XtraEditors.SpinEdit spinEdit1 = new DevExpress.XtraEditors.SpinEdit();
                        spinEdit1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        spinEdit1.Properties.Mask.EditMask = (inputDataType.Equals(InputDataTypes.Decimal)) ? "f" : "f0";
                        //spinEdit1.Size = new System.Drawing.Size(160, 0);
                        spinEdit1.EditValue = null;// aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        spinEdit1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        spinEdit1.Properties.MinValue = -999999999999999;
                        spinEdit1.Properties.MaxValue = 999999999999999;
                        control = spinEdit1;

                        {
                            comboOperations.Properties.Items.Add("=");
                            comboOperations.Properties.Items.Add("<");
                            comboOperations.Properties.Items.Add("<=");
                            comboOperations.Properties.Items.Add(">");
                            comboOperations.Properties.Items.Add(">=");
                            comboOperations.Properties.Items.Add("!="); comboOperations.EditValue = "!=";

                        }
                    }
                    break;
                #endregion
                #region Text
                case InputDataTypes.Text:
                    {

                        DevExpress.XtraEditors.TextEdit textEdit1 = new DevExpress.XtraEditors.TextEdit();
                        //textEdit1.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        textEdit1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        //textEdit1.Size = new System.Drawing.Size(310, 20);
                        textEdit1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        control = textEdit1;
                        {
                            comboOperations.Properties.Items.Add("=");
                            comboOperations.Properties.Items.Add("!=");
                            comboOperations.Properties.Items.Add("Contains"); comboOperations.EditValue = "Contains";
                        }
                    }
                    break;
                #endregion
                #region Free Text
                case InputDataTypes.FreeText:
                    {
                        DevExpress.XtraEditors.MemoEdit memoEdit1 = new DevExpress.XtraEditors.MemoEdit();
                        memoEdit1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        //memoEdit1.Size = new System.Drawing.Size(310, 90);
                        //memoEdit1.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        memoEdit1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        control = memoEdit1;
                        {
                            //comboOperations.Properties.Items.Add("Contains"); comboOperations.EditValue = "Contains";
                        }

                        comboOperations.Visible = false;
                    }
                    break;
                #endregion
                #region Multiselect
                case InputDataTypes.Multiselect:
                    {
                        DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl1 = new DevExpress.XtraEditors.CheckedListBoxControl();
                        checkedListBoxControl1.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        //checkedListBoxControl1.Size = new System.Drawing.Size(310, 120);
                        checkedListBoxControl1.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value; ;

                        //List<string> defaultSelectedValues = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Split(';').ToList();
                        List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION> aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS =
                            (from multiinfo in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONs
                             where multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                             orderby multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_DISPLAY_ORDER.Value
                             select multiinfo).ToList();

                        checkedListBoxControl1.BeginUpdate();
                        checkedListBoxControl1.Items.Clear();

                        for (int i = 0; i < aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS.Count; i++)
                        {
                            CheckedListBoxItem listViewItem = new CheckedListBoxItem();
                            listViewItem.Value = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME;
                            listViewItem.Description = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME;

                            checkedListBoxControl1.Items.Add(listViewItem);

                            //if (defaultSelectedValues.Contains(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME))
                            //{
                            checkedListBoxControl1.SetItemChecked(i, true);

                            //}
                        }
                        checkedListBoxControl1.EndUpdate();

                        control = checkedListBoxControl1;

                        comboOperations.Visible = false;
                    }
                    break;
                #endregion
                #region True & False
                case InputDataTypes.TrueFalse:
                    {

                        DevExpress.XtraEditors.ComboBoxEdit comboTrueFalse = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboTrueFalse.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboTrueFalse.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        //comboTrueFalse.Width = 310;
                        comboTrueFalse.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

                        comboTrueFalse.Properties.Items.BeginUpdate();
                        comboTrueFalse.Properties.Items.Clear();

                        DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION =
                            (from bitOptions in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTIONs
                             where bitOptions.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                             select bitOptions).FirstOrDefault();


                        comboTrueFalse.Properties.Items.Add("Any");
                        comboTrueFalse.Properties.Items.Add(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION.BIT_OPTION_TRUE_DISPLAY_NAME);
                        comboTrueFalse.Properties.Items.Add(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_BIT_OPTION.BIT_OPTION_FALSE_DISPLAY_NAME);

                        comboTrueFalse.Properties.Items.EndUpdate();
                        comboTrueFalse.SelectedIndex = 0;
                        //comboTrueFalse.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboTrueFalse;

                        comboOperations.Visible = false;
                    }
                    break;
                #endregion
                #region Date
                case InputDataTypes.Date:
                    {
                        DevExpress.XtraEditors.DateEdit datePicker = new DevExpress.XtraEditors.DateEdit();

                        DateTime datetimePickerValue = DateTime.Now;

                        //if (String.IsNullOrEmpty(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE))
                        //{
                        datePicker.EditValue = null;
                        //}
                        //else if (aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Equals("GETDATE"))
                        //{
                        //    datePicker.EditValue = DateTime.Now;
                        //}
                        //else
                        //{
                        //    List<string> current_default_string = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Split('-').ToList();
                        //    int day = Convert.ToInt32(current_default_string[0]);
                        //    int month = Convert.ToInt32(current_default_string[1]);
                        //    int year = Convert.ToInt32(current_default_string[2]);
                        //    datetimePickerValue = new DateTime(year, month, day);
                        //    datePicker.EditValue = datetimePickerValue;
                        //}


                        datePicker.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        datePicker.Properties.CalendarTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
                        datePicker.Properties.CalendarTimeProperties.CloseUpKey = new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.F4);
                        datePicker.Properties.CalendarTimeProperties.PopupBorderStyle = DevExpress.XtraEditors.Controls.PopupBorderStyles.Default;
                        //datePicker.Size = new System.Drawing.Size(310, 20);
                        datePicker.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;

                        //DateTimePicker datePicker = new DateTimePicker();
                        //datePicker.Name = 
                        //datePicker.Value = datetimePickerValue;
                        //datePicker.TabIndex =  ;

                        control = datePicker;
                        {
                            comboOperations.Properties.Items.Add("="); comboOperations.EditValue = "=";
                            comboOperations.Properties.Items.Add("<");
                            comboOperations.Properties.Items.Add("<=");
                            comboOperations.Properties.Items.Add(">");
                            comboOperations.Properties.Items.Add(">=");
                            comboOperations.Properties.Items.Add("!=");
                        }
                    }
                    break;
                #endregion
                #region Time
                case InputDataTypes.Time:
                    {
                        DevExpress.XtraEditors.TimeEdit timepicker = new DevExpress.XtraEditors.TimeEdit();
                        DateTime timePickerValue = (aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE.Equals("GETDATE") || String.IsNullOrEmpty(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE) || !DateTime.TryParse(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE, out timePickerValue)) ? DateTime.Now : DateTime.Parse(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE);
                        timepicker.EditValue = null;// timePickerValue;
                        timepicker.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        timepicker.Properties.CloseUpKey = new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.F4);
                        timepicker.Properties.Mask.EditMask = "t";
                        timepicker.Properties.PopupBorderStyle = DevExpress.XtraEditors.Controls.PopupBorderStyles.Default;
                        //timepicker.Size = new System.Drawing.Size(200, 20);
                        timepicker.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value; ;

                        control = timepicker;
                        {
                            comboOperations.Properties.Items.Add("="); comboOperations.EditValue = "=";
                            comboOperations.Properties.Items.Add("<");
                            comboOperations.Properties.Items.Add("<=");
                            comboOperations.Properties.Items.Add(">");
                            comboOperations.Properties.Items.Add(">=");
                            comboOperations.Properties.Items.Add("!=");
                        }
                    }
                    break;
                #endregion
                #region Country
                case InputDataTypes.Country:
                    {
                        DevExpress.XtraEditors.ComboBoxEdit comboCountries = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboCountries.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboCountries.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        //comboCountries.Width = 310;
                        comboCountries.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

                        DAL.AppCode.Countries.LoadAllCountriesToComboBox(comboCountries);
                        comboCountries.Properties.Items.Insert(0, "Any");
                        comboCountries.SelectedIndex = 0;
                        //comboCountries.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboCountries;
                        {
                            comboOperations.Properties.Items.Add("="); comboOperations.EditValue = "=";
                            comboOperations.Properties.Items.Add("!=");
                        }

                        comboOperations.Visible = false;

                    }
                    break;
                #endregion
                #region Nationality
                case InputDataTypes.Nationality:
                    {
                        DevExpress.XtraEditors.ComboBoxEdit comboNationalities = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboNationalities.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboNationalities.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        //comboNationalities.Width = 310;
                        comboNationalities.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

                        DAL.AppCode.Countries.LoadAllNationalitiesToComboBox(comboNationalities);

                        comboNationalities.Properties.Items.Insert(0, "Any");
                        comboNationalities.SelectedIndex = 0;
                        //comboNationalities.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboNationalities;
                        {
                            comboOperations.Properties.Items.Add("="); comboOperations.EditValue = "=";
                            comboOperations.Properties.Items.Add("!=");
                        }

                        comboOperations.Visible = false;

                    }
                    break;
                #endregion
                #region Optional Value
                case InputDataTypes.OptionalValue:
                    {
                        DevExpress.XtraEditors.ComboBoxEdit comboOptionalValue = new DevExpress.XtraEditors.ComboBoxEdit();
                        comboOptionalValue.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();
                        comboOptionalValue.TabIndex = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value;
                        //comboOptionalValue.Width = 310;
                        comboOptionalValue.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;


                        List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION> aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS =
                            (from multiinfo in PRO_DOCSDatabaseDataContext.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONs
                             where multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.Equals(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID)
                             orderby multiinfo.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_DISPLAY_ORDER.Value
                             select multiinfo).ToList();

                        comboOptionalValue.Properties.Items.BeginUpdate();
                        comboOptionalValue.Properties.Items.Clear();
                        comboOptionalValue.Properties.Items.Add("Any");
                        for (int i = 0; i < aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS.Count; i++)
                        {
                            comboOptionalValue.Properties.Items.Add(aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTIONS[i].ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_LIST_OPTION_NAME);
                        }
                        comboOptionalValue.Properties.Items.EndUpdate();
                        comboOptionalValue.SelectedIndex = 0;
                        //comboOptionalValue.EditValue = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DEFAULT_VALUE;
                        control = comboOptionalValue;

                        comboOperations.Visible = false;

                    }
                    break;
                #endregion
            }

            control.Name = aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();

            control.Tag = "VAL_" + aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();

            comboOperations.Tag = "OP_" + aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_ID.ToString();

            ADD_CUSTOM_SEARCH_CONTROL(usedTableLayoutPanel,
                        (Control)comboOperations,
                       control,
                       aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_NAME,
                       aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value);
        }

        /// <summary>
        /// Sets the table default style.
        /// </summary>
        /// <param name="tableLayoutPanel">The table layout panel.</param>
        public void SET_TABLE_DEFAULT_STYLE(TableLayoutPanel tableLayoutPanel)
        {
            tableLayoutPanel.Controls.Clear();
            // Set the BorderStyle to Inset
            tableLayoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
            // Grid has two columns
            tableLayoutPanel.ColumnCount = 2;
            // Grid has two rows
            tableLayoutPanel.RowCount = 1;
            // If grid is full add extra cells by adding column
            tableLayoutPanel.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            // Padding (pixels)within each cell (left, top, right, bottom)
            tableLayoutPanel.Padding = new Padding(1, 1, 4, 5);
            //docking to fill the parent control
            tableLayoutPanel.Dock = DockStyle.Top;
            //Aito sizing
            tableLayoutPanel.AutoSize = true;
            //
            tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
        }
        public void SET_SEARCH_TABLE_DEFAULT_STYLE(TableLayoutPanel tableLayoutPanel)
        {
            tableLayoutPanel.Controls.Clear();
            // Set the BorderStyle to Inset
            tableLayoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
            // Grid has two columns
            tableLayoutPanel.ColumnCount = 3;
            // Grid has two rows
            tableLayoutPanel.RowCount = 1;
            // If grid is full add extra cells by adding column
            tableLayoutPanel.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            // Padding (pixels)within each cell (left, top, right, bottom)
            tableLayoutPanel.Padding = new Padding(1, 1, 4, 5);
            //docking to fill the parent control
            tableLayoutPanel.Dock = DockStyle.Top;
            //Aito sizing
            tableLayoutPanel.AutoSize = true;
            //
            tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
            tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
        }


        public void GET_DOCUMENT_TYPE_STRUCTURE(TableLayoutPanel tableLayoutPanel,
                                                        DAL.Database.ARCHIVE_DOCUMENT_TYPE aCHIVE_DOCUMENT_TYPE)
        {
            tableLayoutPanel.Visible = false;
            tableLayoutPanel.Refresh();
            //1. set the table style
            SET_TABLE_DEFAULT_STYLE(tableLayoutPanel);
            //2. Get the parameters
            List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX> lstAssetCategoriesMoreInfo = aCHIVE_DOCUMENT_TYPE.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEXes.ToList();

            lstAssetCategoriesMoreInfo = lstAssetCategoriesMoreInfo.OrderBy(k => k.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value).ToList();
            //lstAssetCategoriesMoreInfo.Sort(new AssetCategoriesMoreInfoSorter());
            lstAssetCategoriesMoreInfo.ForEach(new Action<PRO_DOCS.DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX>(delegate(PRO_DOCS.DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX)
            {
                ADD_CUSTOM_CONTROL_BY_DATA_TYPE(tableLayoutPanel, aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX);
            }));

            tableLayoutPanel.Visible = true;
            tableLayoutPanel.Refresh();
        }



        public void GET_SEARCH_DOCUMENT_TYPE_STRUCTURE(TableLayoutPanel tableLayoutPanel,
                                                        DAL.Database.ARCHIVE_DOCUMENT_TYPE aCHIVE_DOCUMENT_TYPE)
        {
            tableLayoutPanel.Visible = false;
            tableLayoutPanel.Refresh();
            //1. set the table style
            SET_SEARCH_TABLE_DEFAULT_STYLE(tableLayoutPanel);
            //2. Get the parameters
            List<DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX> lstAssetCategoriesMoreInfo = aCHIVE_DOCUMENT_TYPE.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEXes.ToList();

            lstAssetCategoriesMoreInfo = lstAssetCategoriesMoreInfo.OrderBy(k => k.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX_DISPLAY_ORDER.Value).ToList();
            //lstAssetCategoriesMoreInfo.Sort(new AssetCategoriesMoreInfoSorter());
            lstAssetCategoriesMoreInfo.ForEach(new Action<PRO_DOCS.DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX>(delegate(PRO_DOCS.DAL.Database.ARCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX)
            {
                ADD_CUSTOM_SEARCH_CONTROL_BY_DATA_TYPE(tableLayoutPanel, aRCHIVE_DEPARTMENT_DOCUMENT_TYPE_INDEX);
            }));

            tableLayoutPanel.Visible = true;
            tableLayoutPanel.Refresh();
        }


        #region GET AND SET DYNAMIC INDECIES INPUT VALUES


        public bool VALIDATE_DYNAMIC_INDECIES_INPUT_VALUES(TableLayoutPanel usedTableLayoutPanel, DevExpress.XtraEditors.DXErrorProvider.DXErrorProvider dxErrorProvider)
        {
            dxErrorProvider.ClearErrors();
            List<Guid> parametersValues = new List<Guid>();


            for (int i = 0; i < usedTableLayoutPanel.Controls.Count; i++)
            {
                Control currentControl = usedTableLayoutPanel.Controls[i];

                string control_type_name = currentControl.GetType().Name;
                if (!control_type_name.Equals("Label"))
                {

                    Guid index_id = Guid.Parse(currentControl.Name);
                    string index_value = string.Empty;

                    switch (control_type_name)
                    {
                        case "TimeEdit":
                            index_value = ((DevExpress.XtraEditors.TimeEdit)currentControl).Text;
                            break;
                        case "TextEdit":
                            index_value = ((DevExpress.XtraEditors.TextEdit)currentControl).Text;
                            break;
                        case "SpinEdit":
                            index_value = ((DevExpress.XtraEditors.SpinEdit)currentControl).Text;
                            break;
                        case "ComboBoxEdit":
                            index_value = ((DevExpress.XtraEditors.ComboBoxEdit)currentControl).Text.ToString();
                            break;
                        case "DateEdit":
                            {
                                DevExpress.XtraEditors.DateEdit date_control = (DevExpress.XtraEditors.DateEdit)currentControl;
                                index_value = date_control.Text;
                                if (!string.IsNullOrEmpty(index_value))
                                {
                                    string year = ((DateTime)date_control.EditValue).Year.ToString();
                                    string month = ((DateTime)date_control.EditValue).Month.ToString();
                                    string day = ((DateTime)date_control.EditValue).Day.ToString();
                                    index_value = string.Format("{0}-{1}-{2}", day, month, year);
                                }
                            }
                            break;
                        case "MemoEdit":
                            index_value = ((DevExpress.XtraEditors.MemoEdit)currentControl).Text;
                            break;
                        case "CheckedListBoxControl":
                            {
                                DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl = (DevExpress.XtraEditors.CheckedListBoxControl)currentControl;
                                for (int ind = 0; ind < checkedListBoxControl.Items.Count; ind++)
                                {
                                    string comma = (index_value.Equals(string.Empty)) ? string.Empty : ";";
                                    index_value += (checkedListBoxControl.GetItemChecked(ind)) ? comma + checkedListBoxControl.Items[ind].Value : string.Empty;
                                }
                            }
                            break;
                    }

                    if (Convert.ToBoolean(currentControl.Tag.ToString()))
                    {
                        if (string.IsNullOrEmpty(index_value))
                        {
                            dxErrorProvider.SetError(currentControl, BLL.WIN.Properties.ErrorProviderMessages.Default.InputLeftBlank.Replace("{name}", string.Empty));
                            parametersValues.Add(index_id);
                        }
                    }
                }
            }

            return parametersValues.Count.Equals(0);
        }


        public Dictionary<Guid, string> GET_DYNAMIC_INDECIES_INPUT_VALUES(TableLayoutPanel usedTableLayoutPanel)
        {
            Dictionary<Guid, string> parametersValues = new Dictionary<Guid, string>();


            for (int i = 0; i < usedTableLayoutPanel.Controls.Count; i++)
            {
                Control currentControl = usedTableLayoutPanel.Controls[i];

                string control_type_name = currentControl.GetType().Name;
                if (!control_type_name.Equals("Label"))
                {

                    Guid index_id = Guid.Parse(currentControl.Name);
                    string index_value = string.Empty;

                    switch (control_type_name)
                    {
                        case "TimeEdit":
                            index_value = ((DevExpress.XtraEditors.TimeEdit)currentControl).Text;
                            break;
                        case "TextEdit":
                            index_value = ((DevExpress.XtraEditors.TextEdit)currentControl).Text;
                            break;
                        case "SpinEdit":
                            index_value = ((DevExpress.XtraEditors.SpinEdit)currentControl).Text;
                            break;
                        case "ComboBoxEdit":
                            index_value = ((DevExpress.XtraEditors.ComboBoxEdit)currentControl).Text.ToString();
                            break;
                        case "DateEdit":
                            {
                                DevExpress.XtraEditors.DateEdit date_control = (DevExpress.XtraEditors.DateEdit)currentControl;
                                index_value = date_control.Text;
                                if (!string.IsNullOrEmpty(index_value))
                                {
                                    string year = ((DateTime)date_control.EditValue).Year.ToString();
                                    string month = ((DateTime)date_control.EditValue).Month.ToString();
                                    string day = ((DateTime)date_control.EditValue).Day.ToString();
                                    index_value = string.Format("{0}-{1}-{2}", day, month, year);
                                }
                            }
                            break;
                        case "MemoEdit":
                            index_value = ((DevExpress.XtraEditors.MemoEdit)currentControl).Text;
                            break;
                        case "CheckedListBoxControl":
                            {
                                DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl = (DevExpress.XtraEditors.CheckedListBoxControl)currentControl;
                                for (int ind = 0; ind < checkedListBoxControl.Items.Count; ind++)
                                {
                                    string comma = (index_value.Equals(string.Empty)) ? string.Empty : ";";
                                    index_value += (checkedListBoxControl.GetItemChecked(ind)) ? comma + checkedListBoxControl.Items[ind].Value : string.Empty;
                                }
                            }
                            break;
                    }
                    parametersValues.Add(index_id, index_value);
                }
            }

            return parametersValues;
        }


        public Dictionary<Guid, List<string>> GET_SEARCH_DYNAMIC_INDECIES_INPUT_VALUES(TableLayoutPanel usedTableLayoutPanel)
        {
            Dictionary<Guid, List<string>> parametersValues = new Dictionary<Guid, List<string>>();


            for (int i = 0; i < usedTableLayoutPanel.Controls.Count; i++)
            {
                Control currentControl = usedTableLayoutPanel.Controls[i];

                string control_Tag_name = (currentControl.Tag != null) ? currentControl.Tag.ToString() : string.Empty;
                if (control_Tag_name.Contains("OP_"))
                {
                    Guid current_index_id = Guid.Parse(control_Tag_name.Split('_')[1]);
                    if (!parametersValues.ContainsKey(current_index_id))
                    {
                        List<string> values = new List<string>();
                        values.Add(((DevExpress.XtraEditors.ComboBoxEdit)currentControl).Text);
                        values.Add(string.Empty);
                        parametersValues.Add(current_index_id, values);
                    }


                }
                if (control_Tag_name.Contains("VAL_"))
                {
                    string control_type_name = currentControl.GetType().Name;

                    Guid index_id = Guid.Parse(currentControl.Name);
                    string index_value = string.Empty;

                    switch (control_type_name)
                    {
                        case "TimeEdit":
                            index_value = ((DevExpress.XtraEditors.TimeEdit)currentControl).Text;
                            break;
                        case "TextEdit":
                            index_value = ((DevExpress.XtraEditors.TextEdit)currentControl).Text;
                            break;
                        case "SpinEdit":
                            index_value = ((DevExpress.XtraEditors.SpinEdit)currentControl).Text;
                            break;
                        case "ComboBoxEdit":
                            index_value = ((DevExpress.XtraEditors.ComboBoxEdit)currentControl).Text.ToString();
                            break;
                        case "DateEdit":
                            {
                                DevExpress.XtraEditors.DateEdit date_control = (DevExpress.XtraEditors.DateEdit)currentControl;
                                index_value = date_control.Text;
                                if (!string.IsNullOrEmpty(index_value))
                                {
                                    string year = ((DateTime)date_control.EditValue).Year.ToString();
                                    string month = ((DateTime)date_control.EditValue).Month.ToString();
                                    string day = ((DateTime)date_control.EditValue).Day.ToString();
                                    index_value = string.Format("{0}-{1}-{2}", day, month, year);
                                }
                            }
                            break;
                        case "MemoEdit":
                            index_value = ((DevExpress.XtraEditors.MemoEdit)currentControl).Text;
                            break;
                        case "CheckedListBoxControl":
                            {
                                DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl = (DevExpress.XtraEditors.CheckedListBoxControl)currentControl;
                                for (int ind = 0; ind < checkedListBoxControl.Items.Count; ind++)
                                {
                                    string comma = (index_value.Equals(string.Empty)) ? string.Empty : ";";
                                    index_value += (checkedListBoxControl.GetItemChecked(ind)) ? comma + checkedListBoxControl.Items[ind].Value : string.Empty;
                                }
                            }
                            break;
                    }

                    if (!parametersValues.ContainsKey(index_id))
                    {
                        List<string> values = new List<string>();
                        values.Add("NONE");
                        values.Add(string.Empty);
                        parametersValues.Add(index_id, values);
                    }
                    List<string> current_values = parametersValues[index_id];
                    current_values[1] = index_value;
                    parametersValues[index_id] = current_values;

                    //parametersValues.Add(index_id, index_value);

                }
            }

            return parametersValues;
        }
        public void SET_DYNAMIC_INDECIES_INPUT_VALUES(TableLayoutPanel usedTableLayoutPanel, Dictionary<Guid, string> parametersValues)
        {
            for (int i = 0; i < usedTableLayoutPanel.Controls.Count; i++)
            {
                Control currentControl = usedTableLayoutPanel.Controls[i];

                string control_type_name = currentControl.GetType().Name;
                if (!control_type_name.Equals("Label"))
                {

                    Guid index_id = Guid.Parse(currentControl.Name);
                    if (parametersValues.ContainsKey(index_id))
                    {

                        string index_value = parametersValues[index_id];

                        switch (control_type_name)
                        {
                            case "TimeEdit":
                                ((DevExpress.XtraEditors.TimeEdit)currentControl).EditValue = index_value;
                                break;
                            case "TextEdit":
                                ((DevExpress.XtraEditors.TextEdit)currentControl).EditValue = index_value;
                                break;
                            case "SpinEdit":
                                ((DevExpress.XtraEditors.SpinEdit)currentControl).EditValue = index_value;
                                break;
                            case "ComboBoxEdit":
                                ((DevExpress.XtraEditors.ComboBoxEdit)currentControl).EditValue = index_value;
                                break;
                            case "DateEdit":
                                {
                                    DevExpress.XtraEditors.DateEdit date_control = (DevExpress.XtraEditors.DateEdit)currentControl;


                                    if (!string.IsNullOrEmpty(index_value))
                                    {
                                        List<string> current_saved_date = index_value.Split('-').ToList();

                                        int year = Convert.ToInt32(current_saved_date[2].ToString());
                                        int month = Convert.ToInt32(current_saved_date[1].ToString());
                                        int day = Convert.ToInt32(current_saved_date[0].ToString());
                                        DateTime current_date = new DateTime(year, month, day);
                                        date_control.EditValue = current_date;
                                    }
                                    else
                                    {
                                        date_control.EditValue = null;
                                    }
                                }
                                break;
                            case "MemoEdit":
                                ((DevExpress.XtraEditors.MemoEdit)currentControl).EditValue = index_value;
                                break;
                            case "CheckedListBoxControl":
                                {
                                    if (!string.IsNullOrEmpty(index_value))
                                    {
                                        List<string> current_saved_values = index_value.Split(';').ToList();

                                        DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl = (DevExpress.XtraEditors.CheckedListBoxControl)currentControl;

                                        for (int ind = 0; ind < checkedListBoxControl.Items.Count; ind++)
                                        {
                                            if (current_saved_values.Contains(checkedListBoxControl.Items[ind].Value))
                                            {
                                                checkedListBoxControl.GetItemChecked(ind);
                                            }
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
            }

        }


        #endregion

    }
}
